#include "menuscene.h"

MenuScene::MenuScene()
{
    QPushButton* button1 = new QPushButton("双人对战");
    QPushButton* button2 = new QPushButton("人机对战");
    QPushButton* button3 = new QPushButton("游戏帮助");
    button1->setStyleSheet("height:64px;width:256px");
    button2->setStyleSheet("height:64px;width:256px");
    button3->setStyleSheet("height:64px;width:256px");

    //建立连接，点击按钮 btn1切换到战斗场景
    QObject::connect(button1, &QPushButton::clicked, [&]() {
        MainWindow *mainWindow=(MainWindow *)(getView()->parent()->parent());
        CombatScene* cs=(CombatScene*)mainWindow->combatScene;
        cs->setMode(PVP_MODE);
        mainWindow->setScene(mainWindow->combatScene);
    });

    QObject::connect(button2, &QPushButton::clicked, [&]() {
        MainWindow *mainWindow=(MainWindow *)(getView()->parent()->parent());
        CombatScene* cs=(CombatScene*)mainWindow->combatScene;
        cs->setMode(PVE_MODE);
        mainWindow->setScene(mainWindow->combatScene);
    });


    QObject::connect(button3, &QPushButton::clicked, [&]() {
            QWidget * widget=new QWidget();
            widget->setWindowModality(Qt::ApplicationModal);
            widget->setWindowTitle(tr("游戏帮助"));
            widget->show();
            QLabel *label=new QLabel;
            QLabel *label2=new QLabel;
            label->setText("p1: W跳跃  A向左移动  D向右移动  J普通攻击 K释放技能  S格挡");
            label2->setText("p2:  ↑跳跃   ←向左移动   →向右移动  1普通攻击  2释放技能   ↓格挡");
            QVBoxLayout *layout = new QVBoxLayout;
            layout->addWidget(label);
            layout->addWidget(label2);
            widget->setLayout(layout);
            widget->show();
    });


    // 用于在场景中嵌入widget的部件
    btn1 = addWidget(button1);
    btn2 = addWidget(button2);
    btn3 = addWidget(button3);
}

void MenuScene::init(){
    // 计算 QGraphicsView 的中心位置
    QGraphicsView *view=getView();
    if(view){
         qDebug()<<view;
    }
    if(view->viewport()){
        qDebug()<<view->viewport();
    }
    int centerX = width() / 2;
    int centerY = height() / 2;

    btn1->setPos(centerX - btn1->size().width() / 2, centerY - btn1->size().height()+30);
    btn2->setPos(centerX - btn2->size().width() / 2, centerY +60);
    btn3->setPos(centerX - btn3->size().width() / 2, centerY + btn3->size().height() + 90);

}
void MenuScene::run(){

}
